/*
  ! 如果没有天赋，那就一直重复
  ! Created: 2024/06/15 11:41:41
*/
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
// #define int long long
#define mp(x, y) make_pair(x, y)
#define eb(...) emplace_back(__VA_ARGS__)
#define fro(i, x, y) for (int i = (x); i <= (y); i++)
#define pre(i, x, y) for (int i = (x); i >= (y); i--)
inline void JYFILE19();

using i64 = long long;
using PII = pair<int, int>;

bool ST;
const int N = 1e6 + 10;
const int mod = 998244353;

int n, m;
int a[N], b[N], v[N];

inline void solve() {
  cin >> n >> m;
  fro(i, 1, n) {
    int x, y;
    cin >> x >> y;
    a[i] = x + y;
    b[i] = x - y;
  }
  fro(i, 1, n) {
    cin >> v[i];
  }
  i64 ans = 0;
  fro(i, 1, n) {
    fro(j, i + 1, n) {
      fro(k, j + 1, n) {
        int A = max(abs(a[i] - a[j]), abs(b[i] - b[j]));
        int B = max(abs(a[k] - a[j]), abs(b[k] - b[j]));
        int C = max(abs(a[i] - a[k]), abs(b[i] - b[k]));
        if (A > B) swap(A, B);
        if (B > C) swap(B, C);
        if (A > B) swap(A, B);
        if (B > C) swap(B, C);
        if (B <= 10 || B % 20 == 3) {
          ans += v[i] + v[j] + v[k];
        }
      }
    }
  }
  cout << ans << "\n";
}

signed main() {
  JYFILE19();
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

bool ED;
inline void JYFILE19() {
  freopen("chess.in", "r", stdin);
  freopen("chess.out", "w", stdout);
  srand(random_device{}());
  ios::sync_with_stdio(0), cin.tie(0);
  double MIB = fabs((&ED - &ST) / 1048576.), LIM = 32;
  cerr << "MEMORY: " << MIB << endl, assert(MIB <= LIM);
}